﻿using System.ComponentModel;
using System.Threading;

namespace IssueVision.WCFService.IssueVisionService
{
    /// <summary>
    /// IssueVisionServiceClient class client-side extensions
    /// </summary>
    public partial class IssueVisionServiceClient : INotifyPropertyChanged
    {
        #region "Singleton"
        private static readonly IssueVisionServiceClient instance = new IssueVisionServiceClient("CustomBinding_IIssueVisionService");

        public static IssueVisionServiceClient Instance
        {
            get { return instance; }
        }
        #endregion "Singleton"

        #region "Active Call Count"
        private int _activeCallCount;
        public int ActiveCallCount
        {
            get { return _activeCallCount; }
        }

        public void DecrementCallCount()
        {
            Interlocked.Decrement(ref _activeCallCount);
            if (_activeCallCount == 0)
                OnPropertyChanged("ActiveCallCount");
        }

        public void IncrementCallCount()
        {
            Interlocked.Increment(ref _activeCallCount);
            if (_activeCallCount == 1)
                OnPropertyChanged("ActiveCallCount");
        }
        #endregion "Active Call Count"

        #region "INotifyPropertyChanged Interface implementation"
        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion "INotifyPropertyChanged Interface implementation"
    }
}
